package calculate;

import org.junit.jupiter.api.Test;

/**
 * 基本类型运算
 */
public class BasicTypeOperationTest {
    @Test
    public void arithmetic() {
        System.out.println(3/2);
        System.out.println(2/3);

        System.out.println(3%2);
        System.out.println(2%3);
    }

    @Test
    public void floatAndDouble() {
        float f1 = 3.141592f;
        //3.141592，只能保证6位
        System.out.println("f1=" + f1);
        float f2 = 3.1415926999999F;
        //输出3.1415927，因为存在精度损失；
        System.out.println("f2=" + f2);

        double d1 = 3.1415926999999F;
        //输出3.1415927410125732，因为3.1415926999999F精度损失变为3.1415927，float再转为double(向上转型,宽化),后面的410125732为随机生成；
        System.out.println("d1=" + d1);

        double d2 = 3.1415926999999d;
        System.out.println("d2=" + d2);
        //输出3.1415926999999

        double d3 = 3.1415926999999D;
        System.out.println("d3=" + d3);
        //输出3.1415926999999

        System.out.println("0.05+0.01=" + (0.05+0.01));
        System.out.println("1.0-0.42=" + (1.0-0.42));
        System.out.println("4.015*100=" + 4.015*100);
        System.out.println("123.3/100=" + 123.3/100);
    }
}
